package com.kai.kaispringmvc.xml;

import com.sun.org.apache.bcel.internal.generic.NEW;
import com.sun.org.apache.xpath.internal.operations.Variable;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.InputStream;

/**
 * @author kai
 * @version 1.0
 * @date 2024/7/10
 * @Description 用于解析spring配置文件
 */
public class XMLparser {

    public static String getBasePackage(String xmlFile) {
        SAXReader saxReader = new SAXReader();
        InputStream inputStream = XMLparser.class.getClassLoader().getResourceAsStream(xmlFile);
        try {
            Document document = saxReader.read(inputStream);
            Element rootElement = document.getRootElement();
            Element componentScanElement=
                                       rootElement.element("component-scan");
            Attribute attribute = componentScanElement.attribute("base-package");
            String basePackage = attribute.getText();
            return basePackage;

        } catch (DocumentException e) {
            throw new RuntimeException(e);

        }
        //return "";
    }

}
